package com.xxtx.trade.web.userCenter;

import com.xxtx.trade.common.util.model.Result;
import com.xxtx.trade.sysUser.dto.TradeSysUserDto;
import com.xxtx.trade.sysUser.service.TradeSysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/xxtx/sysUser")
public class SysUserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(SysUserController.class);
    @Autowired
    private TradeSysUserService tradeSysUserService;

    /**
     * 修改短信权限
     */

    @RequestMapping(value = "/update/sms/state", method = RequestMethod.POST)
    public Result updateState(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.updateSmsState(dto);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMessage("系统繁忙，请稍后再试");
            result.setCode(400);
        }
        return result;
    }

    /**
     * 新增人员
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public Result updateOrInsertUser(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.userRegister(dto);
        } catch (Exception e) {
            LOGGER.info("用户注册失败，失败信息为{}", dto);
            result.setMessage("系统繁忙，请稍后再试");
            result.setCode(400);
        }
        return result;
    }

    /**
     * 修改人员
     */
    @RequestMapping(value = "/update/user", method = RequestMethod.POST)
    public Result updateUser(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.updateUser(dto);
        } catch (Exception e) {
            LOGGER.info("用户修改失败，失败信息为{}", dto);
            result.setMessage("系统繁忙，请稍后再试");
            result.setCode(400);
        }
        return result;
    }

    /**
     * 用户登录
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result userLogin(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.userLogin(dto);
        } catch (Exception e) {
            LOGGER.info("用户登录失败，失败信息为{}", dto);
            result.setMessage("系统繁忙，请稍后再试");
            result.setCode(400);
        }
        return result;
    }

    /**
     * 重置密码
     */
    /**
     *
     */
    @RequestMapping(value = "/sys/pwd", method = RequestMethod.POST)
    public Result sysPass(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.sysPassword(dto);
        } catch (Exception e) {
            LOGGER.info("重置密码失败，失败信息为{}", dto);
            result.setMessage("系统繁忙，请稍后再试");
            result.setCode(400);
        }
        return result;
    }

    /**
     * 查看用户设置列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result userList(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.userList(dto);
    }

    /**
     * 启用/禁用
     */
    @RequestMapping(value = "/update/login/state", method = RequestMethod.POST)
    public Result updateLoginState(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.updateLoginState(dto);
    }

    /**
     * 更改密码
     */
    @RequestMapping(value = "/update/password", method = RequestMethod.POST)
    public Result updateUSerPassword(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.updateUSerPassword(dto);
    }


    /**
     * 客户管理列表（代理商用）
     */
    @RequestMapping(value = "/agent/list", method = RequestMethod.POST)
    public Result selectAllAgentUserList(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.selectAgentUserList(dto);
    }

    /**
     * 更改代理商（代理商用）
     */
    @RequestMapping(value = "/agent/update", method = RequestMethod.POST)
    public Result updateAgentUserList(@RequestBody TradeSysUserDto dto) {
        Result<Object> result = new Result<>();
        try {
            result = tradeSysUserService.updateAgent(dto);
        } catch (Exception e) {
            result.setCode(400);
            result.setMessage("失败");
        }
        return result;
    }

    /**
     * 增加代理商（代理商用）
     */
    @RequestMapping(value = "/agent/insert", method = RequestMethod.POST)
    public Result agentInsert(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.inserAgent(dto);
    }

    /**
     * 账号列表
     */
    @RequestMapping(value = "/account/list", method = RequestMethod.POST)
    public Result accountList(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.accountList(dto);
    }


    /**
     * 删除客户信息
     */
    @RequestMapping(value = "/agent/delete", method = RequestMethod.POST)
    public Result agentDelete(@RequestBody TradeSysUserDto dto) {
        return tradeSysUserService.agentDelete(dto);
    }

}
